package com.lvwenguo.controller.bootm;

import com.google.gson.Gson;
import com.lvwenguo.service.bootmServiceInter;
import com.lvwenguo.service.serviceImple.bootmServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/bootmServlet")
public class bootmServlet extends HttpServlet {
    bootmServiceInter bootmServiceImpor=new bootmServiceImple();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       Gson gson=new Gson();
        String s1 = gson.toJson(bootmServiceImpor.selectYuJing());
        String s2 = gson.toJson(bootmServiceImpor.selectRiQi());
        String s3 = gson.toJson(bootmServiceImpor.selectKuCun());
        if(Integer.parseInt(req.getParameter("id"))==0){
            try {
                resp.getWriter().write(s1);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(Integer.parseInt(req.getParameter("id"))==1){
            try {
                resp.getWriter().write(s2);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(Integer.parseInt(req.getParameter("id"))==2){
            try {
                resp.getWriter().write(s3);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }





}
